package mason.dp.observerjdk;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * swing中应用观察者模式的一个小例子
 * @author MasonAir
 *
 */
public class SwingObserverExample {
	JFrame frame;
	public static void main(String[] args) {
		SwingObserverExample soe = new SwingObserverExample();
		soe.go();
	}
	
	public void go() {
		frame = new JFrame();
		JButton button = new JButton("立即执行吗？");
		button.addActionListener(new AngleListener());
		button.addActionListener(new DevilListener());
		frame.getContentPane().add(BorderLayout.CENTER,button);
		frame.setSize(200, 200);
		frame.setLocation(200, 200);
		frame.setVisible(true);
	}
	
	class AngleListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("不要！");
		}
		
	}
	
	class DevilListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("弄死他！");
		}
		
	}

}
